package avicit.bdp.dcs.semistructure.rest;

import avicit.bdp.common.utils.uploads.CatalogBean;
import avicit.bdp.dcs.semistructure.service.FileManageService;
import avicit.platform6.core.rest.msg.ResponseMsg;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @金航数码科技有限责任公司
 * @作者：liyb
 * @邮箱：liyb@avic-digital.com
 * @创建时间： 2023-04-10 10:53
 * @类说明： 文件管理服务类
 * @修改记录：
 */
@RestController
@RequestMapping("/api/bdp/dcs/file/FileManageRest")
@Api(tags = "文件管理接口")
public class FileManageRest {

    private static final Logger logger = LoggerFactory.getLogger(FileManageRest.class);

    @Autowired
    private FileManageService fileManageService;

    @GetMapping("/getCatalogAndFileTree")
    @ApiOperation(value = "查询目录和文件")
    @ApiImplicitParams({
        @ApiImplicitParam(value = "父目录路径", name = "parentCatalogPath"),
        @ApiImplicitParam(value = "jobId", name = "jobId", required = true)
    })
    public ResponseMsg<CatalogBean> getCatalogAndFileTree(@RequestParam(required = false) String parentCatalogPath,
                                                          @RequestParam String jobId) throws Exception {
        ResponseMsg<CatalogBean> responseMsg = new ResponseMsg<>();
        responseMsg.setResponseBody(fileManageService.getCatalogAndFileTree(parentCatalogPath, jobId));
        return responseMsg;
    }

    @GetMapping("/getCatalogAndFileTreeByCatalogPath")
    @ApiOperation(value = "查询目录和文件")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "父目录路径", name = "parentCatalogPath"),
            @ApiImplicitParam(value = "jobId", name = "jobId", required = true)
    })
    public ResponseMsg<List<CatalogBean>> getCatalogAndFileTreeByCatalogPath(@RequestParam String parentCatalogPath,
                                                                             @RequestParam String jobId) throws Exception {
        ResponseMsg<List<CatalogBean>> responseMsg = new ResponseMsg<>();
        responseMsg.setResponseBody(fileManageService.getCatalogAndFileTreeByCatalogPath(parentCatalogPath, jobId));
        return responseMsg;
    }

    @GetMapping("/getFilesByTemplate")
    @ApiOperation(value = "获取模板对应的文件")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "jobId", name = "jobId", required = true),
            @ApiImplicitParam(value = "模板id", name = "templateId", required = true)
    })
    public ResponseMsg<List<String>> getFilesByTemplate(@RequestParam String jobId,
                                                        @RequestParam String templateId) throws Exception {
        ResponseMsg<List<String>> responseMsg = new ResponseMsg<>();
        responseMsg.setResponseBody(fileManageService.getFilesByTemplate(jobId, templateId));
        return responseMsg;
    }

}